﻿<phone:PhoneApplicationPage
    x:Class="BlogApp.WP8.View.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:utils="clr-namespace:BlogApp.WP8.Utils"
    mc:Ignorable="d"
    SupportedOrientations="Portrait"  Orientation="Portrait"
    shell:SystemTray.IsVisible="False"
    DataContext="{Binding MainViewModel, Source={StaticResource Locator}}">

    <phone:PhoneApplicationPage.Resources>
        <DataTemplate x:Key="MyItemHeaderTemplate">
            <Grid Margin="-5,0,0,0">
                <ContentPresenter>
                    <TextBlock Text="{Binding}" Foreground="{StaticResource AccentBrush}" />
                </ContentPresenter>
            </Grid>
        </DataTemplate>
    </phone:PhoneApplicationPage.Resources>

    <phone:PhoneApplicationPage.FontFamily>
        <StaticResource ResourceKey="PhoneFontFamilyNormal"/>
    </phone:PhoneApplicationPage.FontFamily>
    <phone:PhoneApplicationPage.FontSize>
        <StaticResource ResourceKey="PhoneFontSizeNormal"/>
    </phone:PhoneApplicationPage.FontSize>
    <phone:PhoneApplicationPage.Foreground>
        <StaticResource ResourceKey="PhoneForegroundBrush"/>
    </phone:PhoneApplicationPage.Foreground>
    <phone:PhoneApplicationPage.Background>
        <StaticResource ResourceKey="BackgroundBrush"/>
    </phone:PhoneApplicationPage.Background>

    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True" ForegroundColor="{StaticResource AppBarForegroundColor}" BackgroundColor="{StaticResource AccentColor}"  Mode="Default" x:Name="AppBar">
            <shell:ApplicationBarIconButton IconUri="/Assets/appbar.search.png" Text="[search]" x:Name="AppBarIconButtonSearch" Click="AppBarIconButtonSearch_Click" />
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem Text="[imprint]" x:Name="AppBarMenuItemImprint" Click="AppBarMenuItemImprint_Click"/>
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

    <!--LayoutRoot contains the root grid where all other page content is placed-->
    <Grid x:Name="LayoutRoot" Background="{StaticResource BackgroundBrush}">
        <!--<toolkit:PerformanceProgressBar VerticalAlignment="Top" IsIndeterminate="{Binding IsLoading}"/>-->

        <ProgressBar IsIndeterminate="{Binding IsLoading}" IsEnabled="{Binding IsLoading}" VerticalAlignment="Top"/>

        <StackPanel Orientation="Horizontal" Grid.Row="0" Margin="24,16,0,0" VerticalAlignment="Top">
            <Image Source="/Assets/Logo.png" MaxHeight="80"></Image>
            <TextBlock Text="{Binding LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}" Foreground="{StaticResource AccentBrush}" Style="{StaticResource PhoneTextTitle1Style}" TextWrapping="NoWrap" TextTrimming="WordEllipsis"/>
        </StackPanel>

        <phone:Panorama toolkit:TiltEffect.IsTiltEnabled="True" Title=" ">

            <!--Panorama item one-->
            <phone:PanoramaItem Header="{Binding LocalizedResources.HeaderItemNews, Source={StaticResource LocalizedStrings}}" HeaderTemplate="{StaticResource MyItemHeaderTemplate}" Margin="0,-80,0,0" Visibility="{Binding IsOffline, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=reverse}">
                    <phone:LongListSelector ItemsSource="{Binding RecentPostst.Posts}"
                                            Style="{StaticResource LongListSelectorStyle}">
                        <i:Interaction.Behaviors>
                            <utils:IncrementalLoadingBehavior
                                LoadCommand="{Binding MainViewModel.LoadMoreItems, Source={StaticResource Locator}}" />
                        </i:Interaction.Behaviors>
                        <phone:LongListSelector.ItemTemplate>
                            <DataTemplate>
                                <StackPanel Orientation="Vertical" Tap="OnArticleTapped" Margin="0,0,0,12">
                                    <TextBlock
                                        Text="{Binding TitlePlain, Converter={StaticResource UnicodeToTextConverter}}"
                                        Style="{StaticResource PhoneTextNormalStyle}"
                                        FontSize="{StaticResource PhoneFontSizeMedium}"
                                        Foreground="{StaticResource AccentBrush}" TextWrapping="Wrap"
                                        TextTrimming="WordEllipsis" />
                                    <TextBlock
                                        Text="{Binding Excerpt, Converter={StaticResource UnicodeToTextConverter}}"
                                        Style="{StaticResource PhoneTextNormalStyle}"
                                        FontSize="{StaticResource PhoneFontSizeSmall}" TextTrimming="WordEllipsis"
                                        TextWrapping="Wrap" Foreground="{StaticResource TeaserTextBrush}" />
                                </StackPanel>
                            </DataTemplate>
                        </phone:LongListSelector.ItemTemplate>
                    </phone:LongListSelector>
            </phone:PanoramaItem>
            <!--<TextBlock Text="{Binding LocalizedResources.ErrorOffline, Source={StaticResource LocalizedStrings}}"  Visibility="{Binding IsOffline, Converter={StaticResource BoolToVisibilityConverter}}" />-->

            <!--Panorama item two-->
            <phone:PanoramaItem Header="{Binding LocalizedResources.HeaderItemCategory, Source={StaticResource LocalizedStrings}}" HeaderTemplate="{StaticResource MyItemHeaderTemplate}" Margin="0,-80,0,0"  Visibility="{Binding IsOffline, Converter={StaticResource BoolToVisibilityConverter}, ConverterParameter=reverse}">
                <ListBox ItemsSource="{Binding CategoryResult.Categories}" Style="{StaticResource ListBoxStyle}" ItemContainerStyle="{StaticResource ListBoxItemStyle}" Margin="12,0,6,0">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <!--<Border>-->
                            <Grid Background="{StaticResource AccentBrush}" Tap="OnCategoryItem_Tap" HorizontalAlignment="Stretch" VerticalAlignment="Center" Height="50" Margin="0,0,12,12">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto" />
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="auto" />
                                </Grid.ColumnDefinitions>
                                <TextBlock Text="{Binding Title}" Grid.Column="0" HorizontalAlignment="Stretch" Foreground="{StaticResource CategoryBrush}" VerticalAlignment="Center" Margin="12,0,12,0" FontWeight="Bold"/>
                                <TextBlock Text="{Binding PostCount}" Grid.Column="2" HorizontalAlignment="Right" Foreground="{StaticResource CategoryBrush}" VerticalAlignment="Center" Margin="12,0,12,0" FontWeight="Bold"/>
                            </Grid>
                            <!--</Border>-->
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </phone:PanoramaItem>

            <!--Panorama item three-->
            <phone:PanoramaItem Header="{Binding LocalizedResources.AppBarMenuItemSaveOfflineText, Source={StaticResource LocalizedStrings}}" Visibility="{Binding AreOfflinePosts, Converter={StaticResource BoolToVisibilityConverter}}" HeaderTemplate="{StaticResource MyItemHeaderTemplate}" Margin="0,-80,0,0">
                <phone:LongListSelector ItemsSource="{Binding OfflinePosts}" Style="{StaticResource LongListSelectorStyle}">
                    <i:Interaction.Behaviors>
                        <utils:IncrementalLoadingBehavior LoadCommand="{Binding MainViewModel.LoadMoreItems, Source={StaticResource Locator}}" />
                    </i:Interaction.Behaviors>
                    <phone:LongListSelector.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Vertical" Tap="OnArticleTapped"  Margin="0,0,0,12">

                                <toolkit:ContextMenuService.ContextMenu>
                                    <toolkit:ContextMenu IsZoomEnabled="False" Unloaded="ContextMenu_Unload">
                                        <toolkit:MenuItem Header="{Binding LocalizedResources.ContextMenuRemoveEntry, Source={StaticResource LocalizedStrings}}" Click="RemoveMenuItem_Click" DataContext="{Binding Converter={StaticResource TestConverter}}" />
                                    </toolkit:ContextMenu>
                                </toolkit:ContextMenuService.ContextMenu>

                                <TextBlock Text="{Binding TitlePlain, Converter={StaticResource UnicodeToTextConverter}}" Style="{StaticResource PhoneTextNormalStyle}" FontSize="{StaticResource PhoneFontSizeMedium}" Foreground="{StaticResource AccentBrush}" TextWrapping="Wrap" TextTrimming="WordEllipsis" />
                                <TextBlock Text="{Binding Excerpt, Converter={StaticResource UnicodeToTextConverter}}" Style="{StaticResource PhoneTextNormalStyle}" FontSize="{StaticResource PhoneFontSizeSmall}" TextTrimming="WordEllipsis" TextWrapping="Wrap" Foreground="{StaticResource TeaserTextBrush}"/>
                            </StackPanel>
                        </DataTemplate>
                    </phone:LongListSelector.ItemTemplate>
                </phone:LongListSelector>
            </phone:PanoramaItem>

            <phone:PanoramaItem Header="{Binding LocalizedResources.HeaderItemAboutUs, Source={StaticResource LocalizedStrings}}" HeaderTemplate="{StaticResource MyItemHeaderTemplate}" Margin="0,-80,0,0" Background="{StaticResource BackgroundBrush}">
                <ScrollViewer Style="{StaticResource ScrollViewerStyle}">
                    <TextBlock
                        Text="{Binding LocalizedResources.AboutUsText, Source={StaticResource LocalizedStrings}}"
                        Style="{StaticResource PhoneTextNormalStyle}" 
                        FontSize="{StaticResource PhoneFontSizeSmall}" 
                        TextTrimming="WordEllipsis" 
                        TextWrapping="Wrap" 
                        Foreground="{StaticResource TeaserTextBrush}"
                        Margin="12,2,0,12" />
                </ScrollViewer>
            </phone:PanoramaItem>
        </phone:Panorama>
    </Grid>

</phone:PhoneApplicationPage>